gusucode.com > VC++ 基于IE内核功能很齐全的浏览器(支持多标签)-源码程序 > VC++ 基于IE内核功能很齐全的浏览器(支持多标签)-源码程序/code/Explorer/DialogFav.cpp

    //Download by http://www.NewXing.com
// DialogFav.cpp : implementation file
//

#include "stdafx.h"
#include "DialogFav.h"
#include "IEView.h"
#include "Mainfrm.h"
#include <direct.h>


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDialogFav dialog


CDialogFav::CDialogFav(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogFav::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialogFav)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDialogFav::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogFav)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialogFav, CDialog)
	//{{AFX_MSG_MAP(CDialogFav)
	ON_NOTIFY(TVN_SELCHANGED, IDC_DIRTREE, OnSelchangedDirtree)
	ON_WM_SIZE()
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogFav message handlers

BOOL CDialogFav::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
    // First step    // subclassing the DirTreeCtrl
    m_DirTree.SubclassDlgItem( IDC_DIRTREE, this );       
	// next step
    // setting the StartPath if NULL the DirTreeCtrl
    // displays all drives on this PC
    m_DirTree.DisplayTree( m_DefaultPath, 
                           TRUE);

	CRect rc;	
	rc.left=AfxGetApp()->GetProfileInt("Favorite","NormalLeft",400);
	rc.top=AfxGetApp()->GetProfileInt("Favorite","NormalTop",200);
	rc.right=AfxGetApp()->GetProfileInt("Favorite","NormalRight",650);
	rc.bottom=AfxGetApp()->GetProfileInt("Favorite","NormalBottom",500);
	MoveWindow(&rc);
    char szWorkDir[256];    
	_getcwd( szWorkDir, 256 );
    // set the Path to the current Work-Directory
    m_DirTree.SetSelPath( szWorkDir );    
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void  CDialogFav::OnSelchangedDirtree(NMHDR* pNMHDR, LRESULT* pResult)
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Code f黵 die Behandlungsroutine der Steuerelement-Benachrichtigung hier einf黦en
	m_strPathName = m_DirTree.GetFullPath( pNMTreeView->itemNew.hItem);
	if (m_DirTree.GetItemData(pNMTreeView->itemNew.hItem)==0) 
	{		
		CIEView *pView = ((CMainFrame*)AfxGetMainWnd())->GetActiveIEView();
		CFile file;
		if (!file.Open(m_strPathName, CFile::modeRead))
		{
			// an error occured
			AfxMessageBox("无法读取数据!");
			return;
		}
		char *buf = (char*)malloc((file.GetLength()+1)*sizeof(char));
		buf[0]='\0';
		file.Read(buf,file.GetLength());
		file.Close();

		CString s(buf);
		free(buf);
		// we have to remove 
		int pos = s.Find("URL=");
		if (pos == -1) // error ?!??!?
			return;
		s = s.Mid(pos+4);
		pos = s.Find("Modified");
		if (pos != -1) {
			// remove everything after...
			s = s.Left(pos);
		}
		pView->ReadUrlDocument(s);
	}
	else
	{
		m_DirTree.Expand(pNMTreeView->itemNew.hItem,TVE_EXPAND);
	}
	*pResult = 0;
}

void CDialogFav::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	if(m_DirTree.GetSafeHwnd())
	{
		m_DirTree.MoveWindow(1,1,cx-2,cy-2);
	}	
}

void CDialogFav::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	if(!IsIconic())
	{
		CRect rc;
		GetWindowRect(&rc);
		AfxGetApp()->WriteProfileInt("Favorite","NormalLeft",rc.left);
		AfxGetApp()->WriteProfileInt("Favorite","NormalTop",rc.top);
		AfxGetApp()->WriteProfileInt("Favorite","NormalRight",rc.right);
		AfxGetApp()->WriteProfileInt("Favorite","NormalBottom",rc.bottom);
	}
	CDialog::OnClose();
}